// lib
// Zig lib
const std = @import("std");
const time = std.time;
const mem = std.mem;
// C lib
const c: type = @cImport({
    @cInclude("time.h");
});
// pub usingnamespace
pub usingnamespace std.time;
// type
pub const Date: type = struct {
    sec: u8, // Seconds. [0-60] (1 leap second)
    min: u8, // Minutes. [0-59]
    hour: u8, // Hours. [0-23]
    wday: u8, // Days of week. [0-6]
    mday: u8, // Day. [1-31]
    mon: u8, // Month. [1-12]
    year: u16, // Year. -1990
    // other
    yday: u16, // Days of year. [0-365]
    pub fn format(
        self: @This(),
        comptime fmt: []const u8,
        options: std.fmt.FormatOptions,
        writer: anytype,
    ) !void {
        // ignore arg
        _ = options;
        // fn body
        if (fmt.len != 0) std.fmt.invalidFmtError(fmt, self);
        try std.fmt.format(writer, "{}-{}-{}-{} {}:{}:{}", .{
            self.year,
            self.mon,
            self.mday,
            self.wday,
            self.hour,
            self.min,
            self.sec,
        }); // <><> init // <><> move
    }
};
// funcion
/// Get day number.
pub fn getDays() isize {
    const _days: isize = @divTrunc(time.timestamp() + 8 * time.s_per_hour, time.s_per_day);
    return _days;
}
/// Convert seconds to date.
pub fn getDate(seconds: isize) Date {
    const tm: *c.tm = blk: {
        var tm: *c.tm = c.localtime(&seconds);
        tm.tm_year += 1900;
        tm.tm_mon += 1;
        break :blk tm;
    };
    const date: Date = .{
        .sec = @intCast(tm.tm_sec),
        .min = @intCast(tm.tm_min),
        .hour = @intCast(tm.tm_hour),
        .wday = @intCast(tm.tm_wday),
        .mday = @intCast(tm.tm_mday),
        .mon = @intCast(tm.tm_mon),
        .year = @intCast(tm.tm_year),
        .yday = @intCast(tm.tm_yday),
    };
    return date;
}
